<template>
  <div @click="getDetail()" class="main">
    <div @click.stop="onPop" v-show="showPop" class="pop">
      <div class="pop-list-container">
        <div class="pop-list">
          <div @click="pop.func" v-for="(pop, index) in popFunc" class="pop-func" :key="index">
            <img class="pop-img" :src="getIcon(pop.icon)"/>
            <span>{{pop.name}}</span>
          </div>
        </div>
      </div>
      <div @click="onSearchType" class="search-familiar">
        找相似
      </div>
    </div>
    <div class="before-del" v-if="isDel">
      <Loading color="lightskyblue"/>
    </div>
    <img class="main-photo" :src="item.imgUrl" :class="{'awful-img': isAwful}"/>
    <div class="desc">
      <span>{{item.name}}</span><br/>
      <span class="price">￥{{item.price}}</span>
      <span class="payed-num">{{item.payedNum}}人付款</span><br/>
      <div @click.stop="onPop" class="pop-btn">...</div>
    </div>
  </div>
</template>

<script>
import {Loading} from 'vant'

export default {
  name: 'FlowItem',
  data () {
    return {
      showPop: false,
      popFunc: [],
      isAwful: false,
      isDel: false
    }
  },
  components: {
    Loading
  },
  props: {
    item: Object
  },
  created () {
    this.popFunc = [
      {
        name: '不感兴趣',
        icon: 'dislike',
        func: this.dislike
      },
      {
        name: '屏蔽同类',
        icon: 'ban',
        func: this.ban
      },
      {
        name: '图片不适',
        icon: 'awful',
        func: this.awful
      }
    ]
  },
  methods: {
    getDetail () {
      this.$router.push({name: 'ItemDetail', query: {id: this.item.id}})
    },
    onPop () {
      this.showPop = !this.showPop
    },
    getIcon (name) {
      return require(`@/assets/pop/${name}.svg`)
    },
    dislike () {
      this.isDel = true
      setTimeout(() => {
        this.$emit('dislike', undefined, this.item.id)
      }, 800)
    },
    ban () {
      this.isDel = true
      setTimeout(() => {
        this.$emit('dislike', this.item.type, this.item.id)
      }, 800)
    },
    awful () {
      this.isAwful = true
    },
    onSearchType () {
      this.$router.push({name: 'SearchList', params: {searchType: this.item.type}})
    }
  }
}
</script>

<style scoped lang="less">
  .main {
    font-size: 0.25rem;
    background-color: white;
    position: relative;

    .pop {
      width: 100%;
      height: 100%;
      position: absolute;
      display: flex;
      flex-direction: column;
      background: rgba(0, 0, 0, 0.5);
      z-index: 1;

      .pop-list-container {
        flex: 1;
        display: flex;
        align-items: center;

        .pop-list {
          width: 100%;
          height: 2.1rem;
          display: flex;
          margin: 0 0.2rem;
          flex-direction: column;
          justify-content: space-around;

          .pop-func {
            border-radius: 0.3rem;
            height: 0.4rem;
            background-color: white;
            padding: 0.05rem 0;
            display: flex;
            justify-content: center;
            align-items: center;

            .pop-img {
              width: 0.3rem;
              margin-right: 0.1rem;
            }
          }
        }
      }

      .search-familiar {
        flex-shrink: 0;
        background: rgba(0, 0, 0, 0.75);
        padding: 0 0.3rem;
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        height: 0.7rem;
        font-weight: bold;
      }
    }

    .before-del {
      position: absolute;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.8);
      z-index: 2;
    }

    .main-photo {
      width: 100%;
      min-height: 1.7rem;
    }

    .awful-img {
      filter: blur(0.5rem);
    }

    .desc {
      margin: 0 0.2rem;
      padding: 0.1rem 0;
      position: relative;

      .pop-btn {
        font-size: 0.3rem;
        font-weight: bold;
        color: lightgrey;
        text-align: right
      }
    }

    .price {
      font-size: 0.3rem;
      color: orangered
    }

    .payed-num {
      font-size: 0.2rem;
      color: lightgrey
    }
  }

</style>
